<template>
  <div class="divBox" style="padding:10px 0">
    <el-card class="box-card" shadow="never">
      <div slot="header" class="clearfix" style="margin-top:10px">
      </div>
      <el-table
        v-loading="listLoading"
        :data="list"
        size="mini"
        style="width: 100%"
      >
        <el-table-column
          align="center"
          label="ID"
          min-width="50"
          prop="id"
        />
        <el-table-column
          align="center"
          label="头像"
          min-width="50"
          prop="avatar"
        >
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image
                :preview-src-list="[scope.row.avatar]"
                :src="scope.row.avatar"
                style="width: 36px; height: 36px"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="姓名"
          min-width="50"
          prop="name"
        />
        <el-table-column
          align="center"
          label="昵称"
          min-width="50"
          prop="nickname"
        />
        <el-table-column
          align="center"
          label="性别"
          min-width="50"
          prop="gender"
        />
        <el-table-column
          align="center"
          label="邀请人数"
          min-width="50"
          prop="inviteCount"
        />
        <el-table-column align="center" label="操作" min-width="50">
          <template slot-scope="scope">
            <div style="display: inline-block">
              <el-button size="mini" type="text" @click="openInvitee(scope.row.id)">查看邀请人</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :current-page="tableFrom.page"
          :page-size="tableFrom.limit"
          :page-sizes="[20, 40, 60, 80]"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <el-dialog
      :visible.sync="modals"
      class="paymentFooter"
      footerHide
      scrollable
      style="height: 800px"
      title="被邀请者"
      width="900"
      @on-cancel="cancel"
    >
      <el-table
        ref="multipleTable"
        v-loading="Loading"
        :data="querylist"
        size="mini"
        style="width: 100%"
      >
        <el-table-column
          align="center"
          label="ID"
          min-width="50"
          prop="id"
        />
        <el-table-column
          align="center"
          label="头像"
          min-width="50"
          prop="avatar"
        >
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image
                :preview-src-list="[scope.row.avatar]"
                :src="scope.row.avatar"
                style="width: 36px; height: 36px"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="姓名"
          min-width="50"
          prop="name"
        />
        <el-table-column
          align="center"
          label="昵称"
          min-width="50"
          prop="nickname"
        />
        <el-table-column
          align="center"
          label="性别"
          min-width="50"
          prop="gender"
        />
        <el-table-column
          align="center"
          label="邀请时间"
          min-width="50"
          prop="inviteTime"
        />
      </el-table>
      <div class="block mb20">
        <el-pagination
          :current-page="tableFrom1.page"
          :page-size="tableFrom1.limit"
          :page-sizes="[10, 20, 30, 40]"
          :total="total1"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="pageChange1"
        />
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getLiveInviteeList, getLiveInviterList } from '@/api/marketing.js'
import GoodList from '@/components/goodList'

export default {
  components: { GoodList },
  props: {
    liveId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      currentUserid: '',
      listLoading: false,
      list: [],
      tableFrom: {
        page: 1,
        limit: 20
      },
      total: 0,
      querylist: [],
      tableFrom1: {
        page: 1,
        limit: 20
      },
      total1: 0,
      modals: false,
      Loading: false
    }
  },
  watch: {
    liveId(val) {
      if (val) {
        this.getlist()
      }
    }
  },
  created() {
    this.getlist()
  },
  mounted() {

  },
  methods: {
    cancel() {
      this.modals = false
      this.tableFrom1 = {
        page: 1,
        limit: 20
      }
    },
    pageChange1(page) {
      this.tableFrom1.page = page
      this.getDialogList()
    },
    handleSizeChange1(val) {
      this.tableFrom1.limit = val
      this.getDialogList()
    },
    openInvitee(id) {
      this.currentUserid = id
      this.modals = true
      this.getDialogList()
    },
    getDialogList() {
      this.Loading = true
      let parmas = {
        liveId: this.liveId,
        userId: this.currentUserid,
        current: this.tableFrom.page,
        size: this.tableFrom.limit
      }
      getLiveInviteeList(parmas).then(res => {
        this.Loading = false
        this.querylist = res.records
        this.total1 = res.total
      })
    },
    getlist() {
      this.listLoading = true
      let parmas = {
        liveId: this.liveId,
        current: this.tableFrom.page,
        size: this.tableFrom.limit
      }
      getLiveInviterList(parmas).then((res) => {
        this.listLoading = false
        this.list = res.records
        this.total = res.total
        for (let i = 0; i < this.list.length; i++) {
          this.$set(this.list[i], 'msg', 60)
        }
      }).catch((res) => {
        this.listLoading = false
      })
    },
    pageChange(page) {
      this.tableFrom.page = page
      this.getlist()
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val
      this.getlist()
    }
  }
}
</script>
<style lang="scss">
.divBox {
  .el-switch__label--right {
    position: absolute;
    right: 10px;
  }

  .el-switch__label--left {
    position: absolute;
    left: 10px;
  }
}
</style>
